<template>
  <div class="top-category">
    <div class="container">
      <!-- 面包屑 -->
      <xtx-bread>
        <xtx-bread-item to="/">首页</xtx-bread-item>
        <xtx-bread-item>{{ categroyName }}</xtx-bread-item>
      </xtx-bread>

      <!-- 轮播图 -->
      <XtxSlider :list="listRef" :date="5000" :flag="true"></XtxSlider>

      <!-- 全部分类 -->
      <div class="sub-list">
        <h3>全部分类</h3>
        <ul>
          <li v-for="i in categoryList.children" :key="i.id">
            <router-link :to="`/category/sub/${i.id}`">
              <img :src="i.picture" />
              <p>{{ i.name }}</p>
            </router-link>
          </li>
        </ul>
      </div>

      <!-- 二级分类 -->
      <!-- 分类关联商品 -->
      <div class="ref-goods" v-for="item in  categoryList.children" :key="item">
        <div class="head">
          <h3>- {{ item.name }} -</h3>
          <XtxMore to="/" style="position: absolute;top: 20%;right: 20px;" />
        </div>
        <div class="body">
          <goods-item v-for="good in item.goods" :key="good.id" :goods="good" />
        </div>
      </div>
    </div>
  </div>
</template>
<script>

import goodsItem from './components/goods-item.vue'
import { useGetImg } from './service/useGetImg'
export default {
  name: 'Category',
  components: {
    goodsItem
  },
  setup () {
    const {
      listRef,
      categoryList,
      categroyName
    } = useGetImg()
    return {
      listRef,
      categoryList,
      categroyName
    }
  }
}
</script>
<style scoped lang="less">
.top-category {
  h3 {
    font-size: 28px;
    color: #666;
    font-weight: 400;
    text-align: center;
    line-height: 100px;
  }
  .sub-list {
    margin-top: 20px;
    background-color: #fff;
  }
  .sub-list ul {
    display: flex;
    padding: 0 32px;
    flex-wrap: wrap;
    min-height: 160px;
    li {
      width: 168px;
      height: 160px;
      a {
        text-align: center;
        display: block;
        font-size: 16px;
        img {
          width: 100px;
          height: 100px;
        }
        p {
          line-height: 40px;
        }
      }
    }
  }
}
.ref-goods {
  margin-top: 20px;
  background-color: #fff;
  .head {
    position: relative;
    .more {
      position: absolute;
      right: 20px;
      top: 30px;
    }
  }
  .body {
    display: flex;
    justify-content: space-around;
    padding: 0 20px;
    .goods-item {
      display: block;
      width: 220px;
      padding: 20px 30px;
      text-align: center;
      img {
        width: 160px;
        height: 160px;
      }
      p {
        padding-top: 10px;
      }
      .name {
        font-size: 16px;
      }
      .desc {
        color: #999;
        height: 29px;
      }
      .price {
        color: @priceColor;
        font-size: 20px;
      }
    }
  }
}
</style>
